import {
  FormModelImp
} from "./abstract";
// import clone from "clone"


export class FormModel extends FormModelImp {
  store;
  constructor(store) {
    super()
    this.store = store;
  }


  buildModelsList() {

    let modelsList = []

    function deepTransition(map, list, parent) {

      if (Object.keys(map).length == 0) {
        return false
      }

      Object.entries(map).map(([key, value]) => {

        let unit = {
          key: '',
          label: key,
          desc: key,
          prefix: parent ? parent.prefix + '.' + key : key,
          value: value
        }

        list.push(unit)

        if (Object.prototype.toString.call(value) == '[object Object]') {
          unit.children = []
          deepTransition(value, unit.children, unit)
        }

      })

    }

    deepTransition(this.store.models, modelsList, null)
    this.store.modelTree = modelsList

  }

}